import java.sql.*;

//*******************************************************************
//  DatabaseConnector.java       Java Foundations
//
//  Demonstrates the establishment of a JDBC connector.
//*******************************************************************

public class DatabaseConnector
{
    //-----------------------------------------------------------------
    //  Establishes the connection to the database and prints an
    //  appropriate confirmation message.
    //-----------------------------------------------------------------
    public static void main (String args[])
    {
        try
        {
            Connection conn = null;

            // Loads the class object for the mysql driver into the DriverManager.
            //鎶妋ysql椹卞姩鍣ㄧ被瀵硅薄鍔犺浇鍒伴┍鍔ㄧ鐞嗗櫒
            Class.forName("com.mysql.jdbc.Driver");

            // Attempt to establish a connection to the specified database via the
            // DriverManager椹卞姩绠＄悊鍣?
            conn = DriverManager.getConnection("jdbc:mysql://localhost/" +
            "test?user=localhost&password=");

            if (conn != null)
            {
                System.out.println("We have connected to our database!");
                conn.close();
            }

        } catch (SQLException ex) {
            System.out.println("SQLException: " + ex.getMessage());
            ex.printStackTrace();
        } catch (Exception ex) {
            System.out.println("Exception: " + ex.getMessage());
            ex.printStackTrace();
        }
    }
}
